Skip to content

perf(web): reuse completed Markdown prefixes while streaming - #11193

Merged
juliusmarminge merged 3 commits into
legend-perf/timeline-updatesfrom
legend-perf/incremental-markdown
Sep 11, 2026
Merged

perf(web): reuse completed Markdown prefixes while streaming#11193
juliusmarminge merged 3 commits into
legend-perf/timeline-updatesfrom
legend-perf/incremental-markdown

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Sep 11, 2026

Copy link
Copy Markdown
Member

Streaming a response reparses completed code fences on every chunk. Preserve the parsed prefix through a closed top-level fence and reparse the changing suffix, following the completed-block reuse in Legend Markdown.

The existing whole-document transforms, sanitization, source positions and rendering remain in use. Reference definitions, footnotes, CR/CRLF and BOM input fall back to a full parse. Plain prose, completed messages and custom syntax plugins use the existing path. The cache belongs to one streaming renderer.

Five alternating production-browser runs at 1440 × 1000, each with 20 warm-up updates and 120 measured updates:

Client update time Base, including minimap change This layer
Median of run medians 21.5 ms 17.4 ms
Median of run p95s 34.0 ms 30.3 ms

The fixture contains 12 completed TypeScript fences of 30 lines plus growing prose. Every paired run improved; the median reduction is 19.1%. Both builds use the same browser process, origin, fixture and probe. These are synchronous client-update measurements, not provider throughput or user telemetry. Raw samples · Probe, comparison script and parity evidence.

82 focused tests and web typecheck pass. The external CommonMark corpus adds 17,426 full-tree comparisons, including source positions, across its 652 examples. Browser verification retained selected text, DOM identity and exactly the same scroll position through 40 updates. Targeted lint reports two warnings in unchanged code.

This affects streaming Markdown in web and Electron's shared web renderer. Mobile and file/diff viewers are unchanged. Local and remote clients use the same rendering path; no transport, provider or contract changes.

Before, desktop:

Before: completed code blocks at the reading position

After, desktop:

After: identical code layout at the same reading position

Before navigation and streaming, narrow viewport:

https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/cf9292628b42deda/parser-before-demo.webm

After navigation and streaming, narrow viewport:

https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/45f147cf61401e0c/parser-after-demo.webm

Recordings show visual states, not wall-clock speed: the recorder compresses dropped-frame intervals. The table uses separate, unrecorded timing runs; 0.8 seconds of recorder startup was trimmed. Only synthetic fixture data is included. Probes and evidence are not committed.

Integration follow-up: rebased on current main; the integrated stack passes 94 focused Markdown/highlighting tests and 159 timeline tests, plus web typecheck. The timing table remains pinned to the original measured builds.

Model: GPT-6. Harness: Codex.

@juliusmarminge
juliusmarminge added this pull request to stack #11194 September 11, 2026 04:45
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Sep 11, 2026
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 13.6 KiB 15.1 KiB
Codex Thread snapshot wire 7.0 KiB 7.3 KiB
Codex Live turn WebSocket wire 6.5 KiB 7.8 KiB
Codex Live turn WebSocket decoded 57.0 KiB 66.4 KiB
Codex Live turn messages 8 21
Claude Total thread wire 13.6 KiB 15.1 KiB
Claude Thread snapshot wire 7.1 KiB 7.3 KiB
Claude Live turn WebSocket wire 6.5 KiB 7.8 KiB
Claude Live turn WebSocket decoded 57.8 KiB 66.4 KiB
Claude Live turn messages 8 21

Baseline: unavailable · PR result: a660ad9 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 113.9 KiB
  • Claude decoded thread snapshot: 114.6 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@juliusmarminge
juliusmarminge marked this pull request as ready for review September 11, 2026 04:50
@cursor

cursor Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Bugbot is paused — on-demand spend limit reached

Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

Comment thread apps/web/src/markdown-incremental.ts
@macroscopeapp

macroscopeapp Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR introduces stateful AST caching, parser wrapping, position shifting, and automatic fallback decisions in the production streaming Markdown path. Focused parity tests reduce risk, but the new parsing strategy and automatic processing gate are substantial runtime changes.

No code changes detected at a660ad9. Prior analysis still applies.

You can add or adjust custom eligibility rules. Learn more.

@github-actions github-actions Bot added the 📱 Native Change Changes the native fingerprint; merging blocks production OTAs until a new store build ships. label Sep 11, 2026
@juliusmarminge
juliusmarminge force-pushed the legend-perf/incremental-markdown branch from a862924 to a660ad9 Compare September 11, 2026 05:43
@github-actions github-actions Bot removed the 📱 Native Change Changes the native fingerprint; merging blocks production OTAs until a new store build ships. label Sep 11, 2026
@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: c89c418c-586f-4eb9-8adf-91e9ddc98f7e

📥 Commits

Reviewing files that changed from the base of the PR and between 3b9cf6e and a660ad9.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • apps/web/package.json
  • apps/web/src/components/ChatMarkdown.tsx
  • apps/web/src/markdown-incremental.test.tsx
  • apps/web/src/markdown-incremental.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The web app adds an incremental Markdown parser for eligible streaming messages. It caches completed fenced-code prefixes, integrates the parser into ChatMarkdown, and adds tests for parsing equivalence and fallback cases.

Changes

Incremental Markdown streaming

Layer / File(s) Summary
Incremental parser and plugin
apps/web/src/markdown-incremental.ts, apps/web/package.json
Adds cached-prefix parsing, AST cloning, position shifting, full-parse fallbacks, and the exported incremental plugin. Adds required development dependencies.
Streaming renderer integration
apps/web/src/components/ChatMarkdown.tsx
Enables incremental parsing during streaming when fenced code is present and no extra remark plugins are configured.
Parser behavior validation
apps/web/src/markdown-incremental.test.tsx
Tests cached prefixes, streaming positions, line endings, definitions, edits, repeated renders, transformed nodes, and code-fence edge cases.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant ChatMarkdown
  participant IncrementalMarkdownPlugin
  participant MarkdownParser
  ChatMarkdown->>IncrementalMarkdownPlugin: enable for eligible streaming text
  IncrementalMarkdownPlugin->>MarkdownParser: parse current Markdown document
  MarkdownParser-->>ChatMarkdown: return Markdown AST for rendering
Loading

Suggested reviewers: t3dotgg

Merge Risk: ⚪ Minimal · up to a660a

No merge-blocking risk was identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: reusing completed Markdown prefixes during streaming for web performance.
Description check ✅ Passed The description explains what changed, why it changed, scope, performance results, testing, and UI verification. It includes screenshots and videos for the rendering changes. It does not use the templ…
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch legend-perf/incremental-markdown

Comment @coderabbitai help to get the list of available commands.

@juliusmarminge
juliusmarminge merged commit a9dabbf into main Sep 11, 2026
25 checks passed
@juliusmarminge
juliusmarminge deleted the legend-perf/incremental-markdown branch September 11, 2026 06:50
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Sep 11, 2026
## What's Changed
* fix(pr): update labels and reviewers without redundant reloads by @maria-rcks in pingdotgg/t3code#11117
* fix(chat): fold question answers into tool activity by @maria-rcks in pingdotgg/t3code#11014
* fix(usage): flag unpriced model activity instead of showing $0.00 by @maria-rcks in pingdotgg/t3code#11021
* fix(server): let Claude launch args override the derived permission mode by @maria-rcks in pingdotgg/t3code#11026
* fix(editors): accept root paths and Windows servers in Zed remote links by @maria-rcks in pingdotgg/t3code#11044
* fix(web): center pull request unavailable states by @maria-rcks in pingdotgg/t3code#11110
* fix(web): remove sidebar pull request link icon by @maria-rcks in pingdotgg/t3code#11179
* fix(ui): color linked pr counts by aggregate status by @maria-rcks in pingdotgg/t3code#11180
* fix(preview): render website favicons for browser tool activity by @maria-rcks in pingdotgg/t3code#11032
* fix(web): simplify pull request summary sections by @maria-rcks in pingdotgg/t3code#10612
* fix(web): preserve drafts when compacting context by @maria-rcks in pingdotgg/t3code#11103
* fix(server): queue messages during context compaction by @maria-rcks in pingdotgg/t3code#11107
* perf(web): format minimap previews only when opened by @juliusmarminge in pingdotgg/t3code#11181
* perf(web): reuse completed Markdown prefixes while streaming by @juliusmarminge in pingdotgg/t3code#11193
* perf(web): resume syntax highlighting from completed lines by @juliusmarminge in pingdotgg/t3code#11196
* perf(web): preserve completed code-line DOM while streaming by @juliusmarminge in pingdotgg/t3code#11198
* perf(web): huge-thread switch no longer blanks the chat pane by @juliusmarminge in pingdotgg/t3code#11169


**Full Changelog**: pingdotgg/t3code@v0.0.41-nightly.20260911.1520...v0.0.41-nightly.20260911.1533

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.41-nightly.20260911.1533
AIdoesmyjob pushed a commit to AIdoesmyjob/t3code that referenced this pull request Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant